﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteWithControlAccess.Master"
    Inherits="System.Web.Mvc.ViewPage<ProjetoComperio.DataLayer.Entities.Project>" %>

<%@ Import Namespace="ProjetoComperio.Framework.Web.Security.UrlEncrypt" %>
<%@ Import Namespace="ProjetoComperio.DataLayer.Entities" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Meus Projetos
    </h2>
    <div align="right">
    <a href="/Project/Create/"> <img height='25px' width='25px' src='/App_Themes/img/add.png' title='Novo' /> </a>
    </div>
    <div class="Grid">
        <%= Html.Grid(ViewData["GridSource"] as IQueryable<Project>).Columns(
           column => 
           {  
            column.For(x => x.Title).Named("Título");
            column.For(x => x.Description).Named("Descrição"); 
            column.For(x => x.RegisterDate.ToString("dd/MM/yyyy")).Named("Data de Cadastro");

            column.For(x => x.IsActive ? "<img height='25px' width='25px' src='/App_Themes/img/check.png' title='Ativa' />" : "").DoNotEncode().Named("Ativa?");
               
            column.For(x => "<a href='/Project/Edit/" + URLEncrypt.EncryptToString(x.ContributionID.ToString()) + "'>" +
            "<img height='25px' width='25px' src='/App_Themes/img/edit.png' title='Editar' />").DoNotEncode().CellCondition(x => x.IsActive == true);

            column.For(x => "<a action='remove' contributionid='" + URLEncrypt.EncryptToString(x.ContributionID.ToString()) + "' href='javascript:void(0)' urltorequest='/Project/Remove'>" +
            "<img height='25px' width='25px' src='/App_Themes/img/remove.png' title='Excluir' />").DoNotEncode().CellCondition(x => x.IsActive == true);
                         
           }).Attributes(Style =>  "width:100%").Empty("Não existem projetos cadastrados.")
        %>
    </div>
    <br />
    <br />
    <script>

        $("a").filter("[action=remove]").attr("href", "javascript:void(0)");

        $("a").filter("[action=remove]").click(function () {

            if (!confirm("Tem certeza que quer excluir ?"))
                return;

            $.ajax({ type: "POST", url: $("a").filter("[action=remove]").attr("urlToRequest"), data: { "contributionId": $(this).attr("contributionId")} });

            $(this).parent().parent().remove();

        });

    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="head" runat="server">
</asp:Content>
